package com.ricervcvcer.user.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.ArrayList;

@Configuration //配置类
public class SwaggerConfig {

    public static final Contact DEFAULT_CONTACT = new Contact("moge", "http://www.baidu.com", "2521010451@qq.com");

    //获得接口API文档信息
    private ApiInfo apiInfo() {

        return new ApiInfo(
                "ricervcvcer API Document",
                "ricervcvcer用户接口 Swagger2 API 文档",
                "1.0",
                "http://127.0.0.1:8080",
                DEFAULT_CONTACT,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }

    @Bean
    public Docket docket(Environment environment) {
        // 设置要显示swagger的环境
//        Profiles of = Profiles.of("dev", "test");
        // 判断当前是否处于该环境
        // 通过 enable() 接收此参数判断是否要显示
//        boolean b = environment.acceptsProfiles(of);

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
//                .enable(b) //配置是否启用Swagger，如果是false，在浏览器将无法访问
                .select()// 通过.select()方法，去配置扫描接口,RequestHandlerSelectors配置如何扫描接口
                .apis(RequestHandlerSelectors.basePackage("com.ricervcvcer.user.controller"))
                // 配置如何通过path过滤,即这里只扫描请求以/hr开头的接口
//                .paths(PathSelectors.ant("/hr/**"))
                .build();
    }
}